import 'dart:io';

class PhotoAlbum {
  final String id;
  late final String name;
  File? coverImage;
  List<File> photos;
  final DateTime createdAt;

  PhotoAlbum({
    required this.id,
    required this.name,
    this.coverImage,
    required this.photos,
    required this.createdAt,
  });

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'coverImage': coverImage?.path,
      'photos': photos.map((photo) => photo.path).toList(),
      'createdAt': createdAt.toIso8601String(),
    };
  }

  factory PhotoAlbum.fromJson(Map<String, dynamic> json) {
    return PhotoAlbum(
      id: json['id'],
      name: json['name'],
      coverImage: json['coverImage'] != null ? File(json['coverImage']) : null,
      photos: (json['photos'] as List).map((path) => File(path)).toList(),
      createdAt: DateTime.parse(json['createdAt']),
    );
  }
}

